package com.peng.leetcode.tree;

/**
 * CountNodes
 *
 * 222. 完全二叉树的节点个数
 *
 * @author: lupeng6
 * @create: 2021/1/28 14:56
 */
public class CountNodes {

    public static void main(String[] args) {

    }

    private int count = 0;

    public int countNodes(TreeNode root) {
        if (root == null) {
            return 0;
        }
        inOrder(root);
        return count;
    }

    public void inOrder(TreeNode root) {
        if (root == null) {
            return;
        }
        inOrder(root.left);
        count++;
        inOrder(root.right);
    }
}
